<?php

class Client extends BaseClient
{
    const DEFAULT_CLIENT_DISCOUNT = 1;
    const DEFAULT_CLIENT_STATUS   = 1;

    public function rules() {
        return array_merge(parent::rules(),
            array(
                array('email', 'email'),
            )            
        );
    }

    public function beforeSave() {
        if (parent::beforeSave()) {
            $this->client_status_id = self::DEFAULT_CLIENT_STATUS;
            $this->discount_id      = self::DEFAULT_CLIENT_DISCOUNT;

            $this->password = $this->hashPassword($this->password);

            return true;
        }

        return false;
    }

    public function validatePassword($password) {
        return CPasswordHelper::verifyPassword($password, $this->password);
    }

    public function hashPassword($password) {
        return CPasswordHelper::hashPassword($password);
    }

    public static function model($className=__CLASS__)
    {
        return parent::model($className);
    }
}